package cn.wolfcode.redis;

import lombok.Getter;

import java.util.concurrent.TimeUnit;

/**
 * Created by wolfcode-lanxw
 */
@Getter
public enum SeckillRedisKey {
    /**
     *  秒杀商品列表
     *  SeckillRedisKey.SECKILL_PRODUCT_LIST.getRealKey(time + "")
     */
    SECKILL_PRODUCT_LIST("seckillProductList:"),
    /**
     *  订单
     */
    SECKILL_ORDER_HASH("seckillOrderHash:"),
    /**
     *  库存
     *  SeckillRedisKey.SECKILL_STOCK_COUNT_HASH.getRealKey(time + ":" + seckillId)
     */
    SECKILL_STOCK_COUNT_HASH("seckillStockCount:"),
    /**
     *
     */
    SECKILL_REAL_COUNT_HASH("seckillRealCount:"),

    /**
     * 被删除的订单暂时缓存到redis
     */
    SECKILL_ORDER_DLETE_HASH("seckillOrderDeleteHash:"),

    /**
     *  用于判断是否重复登录
     *  SeckillRedisKey.SECKILL_ORDER_SET.getRealKey(time + "")
     */
    SECKILL_ORDER_SET("seckillOrderSet");

    SeckillRedisKey(String prefix, TimeUnit unit, int expireTime){
        this.prefix = prefix;
        this.unit = unit;
        this.expireTime = expireTime;
    }
    SeckillRedisKey(String prefix){
        this.prefix = prefix;
    }
    public String getRealKey(String key){
        return this.prefix+key;
    }
    private String prefix;
    private TimeUnit unit;
    private int expireTime;
}
